<template>
  <div>
    <!-- echarts 要给个ID   并且要设置宽高-->
    <div id="main" v-show="isshow"></div>
    <div id="main1"v-show="!isshow"></div>
    <el-button @click="isshowFn()">按钮</el-button>
  </div>
</template>
<script>
export default {
  name: "storesort",
  mounted() {
    let _self = this;
    _self.$nextTick(function(){
        _self.echartsInit();
    })
    
   
  },
  data(){
    return{
        isshow:true
    }
  },
  methods: {
    isshowFn(){
        let _self = this;
        _self.isshow = !_self.isshow;
            if(!_self.isshow){
                // 是异步的
                // 异步的情况如果涉及到了v-if的话需要把v-if变成v-show
                
                _self.$nextTick(function(){
                    // 真实的DOM必须渲染完毕才能进来
                    // 什么情况下用
                    // 1.Vue里面使用Jq的插件
                    // 2.echarts
                    // 3.获取页面渲染后的DOM的真实的宽高
                    _self.echartsInit1();
                })
                //  _self.echartsInit1();
            }
    },
    echartsInit1(){
          let _self= this;
      var chartDom = document.getElementById("main1");//
      var myChart = _self.$echarts.init(chartDom);//初始化 创建
      var option;

     option = {
  title: [
    {
      text: 'Tangential Polar Bar Label Position (middle)'
    }
  ],
  polar: {
    radius: [30, '80%']
  },
  angleAxis: {
    max: 4,
    startAngle: 75
  },
  radiusAxis: {
    type: 'category',
    data: ['a', 'b', 'c', 'd']
  },
  tooltip: {},
  series: {
    type: 'bar',
    data: [2, 1.2, 2.4, 3.6],
    coordinateSystem: 'polar',
    label: {
      show: true,
      position: 'middle',
      formatter: '{b}: {c}'
    }
  }
};
      option && myChart.setOption(option);
    },
    echartsInit() {
        let _self= this;
      var chartDom = document.getElementById("main");//
      var myChart = _self.$echarts.init(chartDom);//初始化 创建
      var option;
     
      option = {
        title: {
          text: "Stacked Area Chart"
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985"
            }
          }
        },
        legend: {
          data: ["Email", "Union Ads", "Video Ads", "Direct", "Search Engine"]
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true
        },
        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            data: ["MonMonMonMonMon", "TueTueTueTueTueTueTue", "WedWedWedWedWedWedWedWedWed", "ThuThuThuThuThuThuThuThu", "FriFriFriFriFriFriFriFri", "SatSatSatSatSatSatSatSat", "SunSunSunSunSunSunSunSunSunSunSun"],
            axisLabel:{
                rotate:45
            }
            // X轴文字显示不全
          }
        ],
        yAxis: [
          {
            type: "value"
          }
        ],
        series: [
          {
            name: "Email",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series"
            },
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: "Union Ads",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series"
            },
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: "Video Ads",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series"
            },
            data: [150, 232, 201, 154, 190, 330, 410]
          },
          {
            name: "Direct",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series"
            },
            data: [320, 332, 301, 334, 390, 330, 320]
          },
          {
            name: "Search Engine",
            type: "line",
            stack: "Total",
            label: {
              show: true,
              position: "top"
            },
            areaStyle: {},
            emphasis: {
              focus: "series"
            },
            data: [820, 932, 901, 934, 1290, 1330, 1320]
          }
        ]
      };

      option && myChart.setOption(option);
    }
  }
};
</script>
<style scoped>
    #main{
        width: 600px;
        height: 600px;
    }
    #main1{
        width: 600px;
        height: 600px;
    }
</style>